{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "from hfnet.datasets.colmap_utils.read_model import read_model\n",
    "from hfnet.settings import DATA_PATH"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "name = 'robotcar/models/focal_from_ref_db'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "cam, im, pts = read_model(str(Path(DATA_PATH, name)), ext='.bin')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "track_length = np.array([len(p.image_ids) for p in pts.values()])\n",
    "error = np.array([p.error for p in pts.values()])\n",
    "matched_ratio = np.array([np.mean(i.point3D_ids>=0) for i in im.values()])\n",
    "num_kpts = np.array([len(i.point3D_ids) for i in im.values()])\n",
    "registered = np.array([np.any(i.point3D_ids>=0) for i in im.values()])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(name)\n",
    "print('Num points: ', len(pts))\n",
    "print('Registered: ', registered.sum())\n",
    "print('Track length: ', np.mean(track_length), np.median(track_length))\n",
    "print('Error: ', np.mean(error), np.median(error))\n",
    "print('Num keypoints: ', np.mean(num_kpts), np.median(num_kpts))\n",
    "print('Matched ratio: ', np.mean(matched_ratio), np.median(matched_ratio))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "robotcar/models/focal_from_ref_db\n",
      "Num points:  2525451\n",
      "Registered:  20862\n",
      "Track length:  4.710539622427835 3.0\n",
      "Error:  1.1104463983370143 0.9917682115463519\n",
      "Num keypoints:  987.0812482024734 970.0\n",
      "Matched ratio:  0.5873123103285909 0.5993051476209252\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "robotcar/models/sift_model\n",
      "Num points:  6869225\n",
      "Registered:  20862\n",
      "Track length:  5.343981307935029 4.0\n",
      "Error:  0.6656170693835156 0.4899262914543929\n",
      "Num keypoints:  4557.614083021762 4409.0\n",
      "Matched ratio:  0.38989835764117714 0.3935574982591231\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aachen/models/sp-nms4_model\n",
      "Num points:  684990\n",
      "Registered:  4324\n",
      "Track length:  5.865941108629323 4.0\n",
      "Error:  1.2959421514395788 1.2364830452354432\n",
      "Num keypoints:  2431.5582255083177 2576.0\n",
      "Matched ratio:  0.3700134406483974 0.338486114116724\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aachen/models/sift_model\n",
      "Num points:  1899775\n",
      "Registered:  4327\n",
      "Track length:  5.847865141924702 4.0\n",
      "Error:  0.6926995829514279 0.5770622253768403\n",
      "Num keypoints:  10451.853974121996 10229.5\n",
      "Matched ratio:  0.24868336834044444 0.18796852084515603\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CMU"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "slices = [2, 3, 4, 5, 6, 7, 8, 9, 10, 17]\n",
    "name = 'cmu/slice{}/models/focal_from_ref_db'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "track_length = []\n",
    "error = []\n",
    "matched_ratio = []\n",
    "num_kpts = []\n",
    "registered = []\n",
    "num = []\n",
    "\n",
    "for s in slices:\n",
    "    cam, im, pts = read_model(str(Path(DATA_PATH, name.format(s))), ext='.bin')\n",
    "    track_length.append(np.array([len(p.image_ids) for p in pts.values()]))\n",
    "    error.append([p.error for p in pts.values()])\n",
    "    matched_ratio.append(np.array([np.mean(i.point3D_ids>=0) for i in im.values()]))\n",
    "    num_kpts.append(np.array([len(i.point3D_ids) for i in im.values()]))\n",
    "    registered.append(np.array([np.any(i.point3D_ids>=0) for i in im.values()]))\n",
    "    num.append(len(pts))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "track_length = np.concatenate(track_length)\n",
    "error = np.concatenate(error)\n",
    "matched_ratio = np.concatenate(matched_ratio)\n",
    "num_kpts = np.concatenate(num_kpts)\n",
    "registered = np.concatenate(registered)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(name)\n",
    "print('Num points: ', np.sum(num))\n",
    "print('Registered: ', registered.sum())\n",
    "print('Track length: ', np.mean(track_length), np.median(track_length))\n",
    "print('Error: ', np.mean(error), np.median(error))\n",
    "print('Num keypoints: ', np.mean(num_kpts), np.median(num_kpts))\n",
    "print('Matched ratio: ', np.mean(matched_ratio), np.median(matched_ratio))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cmu/slice{}/models/focal_from_ref_db\n",
      "Num points:  552591\n",
      "Registered:  4191\n",
      "Track length:  4.952100197071614 4.0\n",
      "Error:  1.1899668798828889 1.074951788534993\n",
      "Num keypoints:  1454.2037699832974 1446.0\n",
      "Matched ratio:  0.4551297870897866 0.4534769833496572\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "cmu/slice{}/models/sift_model\n",
      "Num points:  960928\n",
      "Registered:  4191\n",
      "Track length:  4.110481742648773 3.0\n",
      "Error:  1.0 1.0\n",
      "Num keypoints:  942.4664757814364 910.0\n",
      "Matched ratio:  1.0 1.0\n"
     ]
    }
   ],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
